/*
 *  Mesh.h
 *  SypXIPhone
 *
 *  Created by Luv Khemani on 5/13/10.
 *  Copyright 2010 Luv Khemani. All rights reserved.
 *
 */
#pragma once
#ifndef SYPX_MESH
#define SYPX_MESH

#include "Types.h"
#include "MeshPart.h"
#include "Resource.h"

namespace SypX
{
	///Mesh type. Indexed meshes have an indexed array referencing vertices to
	///draw a mesh allowing a vertex to be referenced more than once, thus improving memory efficiency and performance.
	///NonIndexed Meshes only have vertices which are drawn in order without any reuse of repeated vertices.
	enum MeshType
	{
		INDEXEDMESH,
		NONINDEXEDMESH,
	};

	enum PrimitiveType
	{
		TRIANGLES = 0x0004,
		LINES = 0x0001,
		LINELOOP = 0x0002,
	};
	///A Mesh holds vertex/normal/UV/mesh attribute data, as well as index data.
	///A Mesh consists of one or more MeshParts defining seperate drawcalls. MeshParts
	///are required when different materials/shaders/textures used for different parts of the mesh
	class SYPXAPI Mesh : public Resource
	{
	public:
		///Mesh Constructor
		Mesh();
		///Mesh Deconstructor
		virtual ~Mesh();
		///Generates vertex information for a quad
		void initAsQuad(float width, float height, float depth = 0, bool genColor = false);
		///Resizes the Mesh(must be initAsQuad() prior to calling this)
		void resizeQuad(float width, float height);
		///Generates vertex information for a circle, smoothness defines number of edges (minimum of 4)
		void initAsCircle(float radius, int smoothness, float depth = 0, bool genColor = false);
		///Returns a reference to the data FloatArray
		FloatArray& getDataArrayRef();
		///Returns the number of vertices contained in this mesh
		UShort getNumVertices() const;
		///Sets the stride for the vertex data
		void setStride(UByte s);
		///Returns stride of mesh
		UByte getStride();
		///Returns whether the mesh has color attributes
		bool usesColor();
		///Sets the primitive Type to use when drawing this mesh
		void setPrimitiveType(PrimitiveType type);
		///Returns the PrimitiveType of the mesh
		PrimitiveType getPrimitiveType();
	protected:
        ///Describes whether this mesh has color attributes
		bool hasColor;
		PrimitiveType primType;
		UByte stride;	//Number of bytes seperating each unique vertex
		FloatArray data;
		UShortArray index;
		std::vector<MeshPart> parts;
		MeshType meshType;
	};

}

#endif

